  google.load("maps", "2.x");
  
  var map ;
  var redicon ;

  //<![CDATA[
  function load() {
    if (GBrowserIsCompatible()) {
      map = new GMap2(document.getElementById("map"));
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
      map.addControl(new GScaleControl()) ;
      map.addControl(new GOverviewMapControl()) ;
      map.setCenter(new GLatLng(37.4419, -122.1419), 10);

      GEvent.addListener(map, 'click', function(overlay, point)  // Add a click listener
      {
        if (overlay)
        {
        } else if (point) 
        {
          addpoint( point ) ;
        }
      });

      redicon = new GIcon();
      redicon.shadow = "";
      redicon.iconSize = new GSize(10, 10);
      redicon.iconAnchor = new GPoint(0, 0);
      redicon.infoWindowAnchor = new GPoint(0, 0);
      redicon.infoShadowAnchor = new GPoint(0, 0);
      redicon.image = "/themes/default/mapred.png" ;
      
      datadraw();

    }
    else
    {
      document.getElementById("map").innerHTML = "<h1>Browser not compatible with Google Maps. Sorry...</h1>" ;
    }    
  }  

// Add a point to the textarea markerdata...

   function addpoint( point ) 
   {
    document.data.markerdata.value += point.toUrlValue() + ";" ;
    datadraw();
   }

// Clear the work text area and overlays...

   function dataclear() 
   {
    document.data.markerdata.value = "" ;
    map.clearOverlays() ;
   }

// Draw the markers associated with the points clicked...

   function datadraw() 
   {
    map.clearOverlays() ;
    var wrkar = [] ;
    if ( document.data.markerdata.value )     // Check for markerdata
    {
     wrkar = dataparse( document.data.markerdata.value ) ;
     for (var i = 0; i < wrkar.length; i++)
     {
      map.addOverlay( new GMarker(wrkar[i],redicon) ) ;
     }
    }    
   }

// Center the map on the first marker found...

   function datacenter() 
   {
    var point ;
    var wrkar = [] ;
    if ( document.data.markerdata.value )     // Check for markerdata
    {
     wrkar = dataparse( document.data.markerdata.value ) ;
    }    
    if ( wrkar[0] )
    {
     point = wrkar[0] ;
    } else if ( document.data.savedata.value )      // Check for saved data
    {
     wrkar = dataparse( document.data.savedata.value ) ;
     if ( wrkar[0] )
     {
      point = wrkar[0] ;
     }
    }
    if ( point )
    {
     map.setCenter(point,8);

    } else
    {
     alert( "No points entered yet. Cannot center map." ) ;
    }
   }

// Parse the textarea data into a points array...

   function dataparse( points )
   {
    points = points.substr(0,points.length - 1) ;
    var linar = points.split(";") ;        // Break each point by line break
    var wrkar = [] ;
    var pntar = [] ;
    for (var i = 0; i < linar.length; i++)
    {
     wrkar = linar[i].split(",",2) ;        // Break each point into x and y
     pntar.push( new GLatLng(parseFloat(wrkar[0]), parseFloat(wrkar[1])) ) ; 
    }
    return pntar ;
   }